package util

import (
"crypto/md5"
"crypto/rand"
"encoding/base64"
"encoding/hex"
"io"
)

//GetMd5String 生成32位md5字串
func GetMd5String(s string) string {
	h := md5.New()
	h.Write([]byte(s))
	return hex.EncodeToString(h.Sum(nil))
}

//UniqueID 生成Guid字串
func UniqueID() (string, error) {
	b := make([]byte, 48)

	if _, err := io.ReadFull(rand.Reader, b); err != nil {
		return "", err
	}

	return GetMd5String(base64.URLEncoding.EncodeToString(b)), nil
}
